  
<template>
    <div class="edu-page-warp">
        <div>
            <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
                <el-tab-pane label="标签维护" name="nonPublic"></el-tab-pane>
                <el-tab-pane label="荣誉课程模块维护" name="public"></el-tab-pane>
                <el-container>
                    <el-aside width="40%" style="min-height:300px;">
                        <el-row style="padding:15px 15px 15px 0;">
                            <el-col :span="18">
                                <el-input v-model="filterText" :placeholder="'快捷查询'">
                                    <!-- @keyup.enter.native="getProfessions" -->
                                    <i
                                        slot="suffix"
                                        class="el-icon-search"
                                        style="margin-top:10px;cursor:pointer"
                                    ></i>
                                </el-input>
                                <!-- @click="getProfessions" -->
                            </el-col>
                            <el-col :span="4" class="float-right">
                                <el-button plain size="mini" @click="addCourseCategory">添加</el-button>
                            </el-col>
                        </el-row>
                        <el-row>
                            <!-- <div> -->
                            <el-tree
                                class="filter-tree tree"
                                :data="treeData"
                                :props="defaultProps"
                                default-expand-all
                                :filter-node-method="filterNode"
                                :highlight-current="true"
                                @node-click="nodeClick"
                                ref="tree"
                            ></el-tree>
                            <!-- </div> -->
                        </el-row>
                    </el-aside>
                    <!-- 右边内容 -->
                    <el-container>
                        <el-main>
                            <!-- 标签维护 -->
                            <el-row  v-if="labType==2">
                                <el-form
                                    ref="detailForm"
                                    :model="detailForm"
                                    label-position="right"
                                    label-width="140px"
                                >
                                    <el-row>
                                        <div class="float-left">
                                            <div class="edu-page-title">标签详情</div>
                                        </div>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="12">
                                            <el-form-item :label="'标签名称（中文）：'">
                                                <el-input
                                                    v-model="detailForm.nameCN"
                                                    type="text"
                                                    placeholder="请输入中文名称"
                                                    style="width:100%"
                                                    maxlength="50"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="12">
                                            <el-form-item :label="'培养层次：'">
                                                <el-select
                                                    v-model="detailForm.trainingLevel"
                                                    style="width:100%"
                                                    clearable
                                                >
                                                    <el-option
                                                        v-for="item in options.trainingLevel"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value"
                                                    />
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20" v-if="detailForm.parentID != 0">
                                        <el-col :span="12">
                                            <el-form-item :label="'归属标签'+' '+': '">
                                                <el-select
                                                    style="width: 100%;"
                                                    v-model="detailForm.courseType"
                                                    :placeholder="'请选择归属标签'"
                                                    clearable
                                                >
                                                    <el-option
                                                        v-for="item in options.courseType"
                                                        :key="item.id"
                                                        :label="item.label"
                                                        :value="item.id"
                                                    ></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="20">
                                            <el-form-item :label="'年级：'">
                                                <el-date-picker
                                                v-model="detailForm.startYear"
                                                value-format="yyyy"
                                                format="yyyy"
                                                type="year"
                                                placeholder="选择年">
                                                </el-date-picker>
                                                <span>~</span>
                                                <el-date-picker
                                                v-model="detailForm.endYear"
                                                value-format="yyyy"
                                                format="yyyy"
                                                type="year"
                                                placeholder="选择年">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="20">
                                            <el-form-item :label="'标签简称：'" prop="shortName">
                                                <el-input
                                                    v-model="detailForm.shortName"
                                                    type="text"
                                                    placeholder="请输入中文名称"
                                                    style="width:100%"
                                                    maxlength="50"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-row>
                            <!-- 荣誉课程模块维护 -->
                            <el-row  v-if="labType==1">
                                <el-form
                                    ref="detailForm"
                                    :model="detailForm"
                                    label-position="right"
                                    label-width="140px"
                                >
                                    <el-row>
                                        <div class="float-left">
                                            <div class="edu-page-title">荣誉课程模块详情</div>
                                        </div>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="12">
                                            <el-form-item :label="'荣誉课程模块名称：'">
                                                <el-input
                                                    v-model="parentName"
                                                    type="text"
                                                    placeholder=""
                                                    style="width:100%"
                                                    :disabled="detailForm.parentID != 0"
                                                    maxlength="50"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="12">
                                            <el-form-item :label="'培养层次：'">
                                                <el-select
                                                    v-model="detailForm.trainingLevel"
                                                    style="width:100%"
                                                    clearable
                                                >
                                                    <el-option
                                                        v-for="item in options.trainingLevel"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value"
                                                    />
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="12">
                                            <el-form-item :label="'方向：'">
                                                <el-input
                                                    v-model="sonName"
                                                    type="text"
                                                    placeholder=""
                                                    style="width:100%"
                                                    :disabled="detailForm.parentID == 0"
                                                    maxlength="50"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="20">
                                            <el-form-item :label="'年级：'">
                                                <el-date-picker
                                                v-model="detailForm.startYear"
                                                value-format="yyyy"
                                                format="yyyy"
                                                type="year"
                                                placeholder="选择年">
                                                </el-date-picker>
                                                <span>~</span>
                                                <el-date-picker
                                                v-model="detailForm.endYear"
                                                value-format="yyyy"
                                                format="yyyy"
                                                type="year"
                                                placeholder="选择年">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-row>
                            <!-- 课程列表 -->
                            <el-row v-if="labType==1">
                                <div class="float-right addCourseBtn">
                                    <!-- <el-button type="primary" size="mini" @click="addCourse" :disabled="!this.detailForm.id">课程维护</el-button> -->
                                    <el-button type="primary" size="mini" @click="addCourse">课程维护</el-button>
                                </div>
                            </el-row>
                            <!-- 添加类别-->
                            <el-dialog
                                :title="dialogTitle"
                                :visible.sync="showCourseDialog"
                                width="40%"
                                @close="resetFormValidate()"
                                :close-on-click-modal="false"
                                :close-on-press-escape="false"
                            >
                                <el-form
                                    ref="classifyForm"
                                    :model="classifyForm"
                                    :rules="courseRules"
                                    label-width="150px"
                                    label-position="right"
                                    size="mini"
                                    class="bg-white"
                                >
                                    <el-row :gutter="20">
                                        <el-col :span="20" :offset="1">
                                            <el-form-item :label="labType == 2?'标签名称（中文）：':'名称：'" prop="name">
                                                <el-input
                                                    v-model="classifyForm.name"
                                                    type="text"
                                                    placeholder="请输入中文名称"
                                                    style="width:100%"
                                                    maxlength="50"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="20" :offset="1">
                                            <el-form-item :label="'培养层次：'" prop="trainingLevel">
                                                <el-select
                                                    v-model="classifyForm.trainingLevel"
                                                    style="width:100%"
                                                    clearable
                                                >
                                                    <el-option
                                                        v-for="item in options.trainingLevel"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value"
                                                    />
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="20" :offset="1">
                                            <el-form-item :label="labType == 2?'归属标签：':'归属模块：'">
                                                <el-select
                                                    style="width: 100%;"
                                                    v-model="classifyForm.courseType"
                                                    :placeholder="'请选择'"
                                                    clearable
                                                >
                                                    <el-option
                                                        v-for="item in classifyOptions.courseType"
                                                        :key="item.id"
                                                        :label="item.label"
                                                        :value="item.id"
                                                    ></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20">
                                        <el-col :span="23" :offset="1">
                                            <el-form-item :label="'年级：'" prop="startYear">
                                                <el-date-picker
                                                v-model="classifyForm.startYear"
                                                type="year"
                                                value-format="yyyy"
                                                format="yyyy"
                                                placeholder="选择年">
                                                </el-date-picker>
                                                <span>~</span>
                                                <el-date-picker
                                                v-model="classifyForm.endYear"
                                                value-format="yyyy"
                                                format="yyyy"
                                                type="year"
                                                placeholder="选择年">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="20" v-if="labType == 2">
                                        <el-col :span="20" :offset="1">
                                            <el-form-item :label="'标签简称：'" prop="shortName">
                                                <el-input
                                                    v-model="classifyForm.shortName"
                                                    type="text"
                                                    placeholder="请输入中文名称"
                                                    style="width:100%"
                                                    maxlength="50"
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                                <el-row>
                                    <el-col :span="24">
                                        <div class="float-right">
                                            <el-button
                                                @click="cancelAddCourseLab"
                                            >{{ $t('common.btn.cancel') }}</el-button>
                                            <el-button
                                                type="primary"
                                                @click="addCourseLabs"
                                            >{{ $t('common.btn.confirm') }}</el-button>
                                        </div>
                                    </el-col>
                                </el-row>
                            </el-dialog>
                            <!-- 添加课程 -->
                            <!-- <el-dialog
                                :title="courseSetting"
                                :visible.sync="showAddCourseDialog"
                                width="50%"
                                :close-on-click-modal="false"
                                :close-on-press-escape="false"
                            >
                                <el-form
                                    ref="addCourseForm"
                                    :model="addCourseForm"
                                    label-width="80px"
                                    label-position="right"
                                    size="mini"
                                    class="bg-white"
                                >
                                    <el-row>
                                        <el-col :span="10">
                                            <el-form-item :label="'开课学院:'" prop="college">
                                                <DictSelect
                                                    v-model="queryForm.college"
                                                    :data="options.college"
                                                    @change="getProfession(queryForm.college)"
                                                ></DictSelect>
                                            </el-form-item>
                                        </el-col>
                                         <el-col :span="10">
                                    <el-form-item :label="'课程代码/课程名称:'" prop="condition">
                                          <el-input
                                            v-model="queryForm.condition"
                                             placeholder="输入课程代码或课程名称"
                                             suffix-icon="el-icon-search"
                                            clearable
                                             @keyup.enter.native="getCondition"
                                             v-if="$store.state.language == 'cn'"
                                         />
                                          </el-form-item>                                     
                                        </el-col>  
                                    </el-row>
                                </el-form>
                                <el-table
                                    ref="multipleTable"
                                    :data="addCourseForm"
                                    stripe
                                    size="mini"
                                    @selection-change="addCourseSelectionChange"
                                >
                                    <el-table-column type="selection" width="40"></el-table-column>
                                    <el-table-column :label="'课程代码'" fixed="left" width="120">
                                        <template slot-scope="props">{{ props.row.code}}</template>
                                    </el-table-column>
                                    <el-table-column :label="'课程名称'">
                                        <template slot-scope="props">{{ props.row.name}}</template>
                                    </el-table-column>
                                    <el-table-column :label="'开课学院'">
                                        <template slot-scope="props">{{ props.row.college}}</template>
                                    </el-table-column>
                                    <el-table-column :label="'学分'" width="120">
                                        <template slot-scope="props">{{ props.row.credits}}</template>
                                    </el-table-column>
                                    <el-table-column :label="'学时'" width="120">
                                        <template slot-scope="props">{{ props.row.period}}</template>
                                    </el-table-column>
                                </el-table>

                                <el-row style="margin-top:15px;">
                                    <el-col :span="24">
                                        <div class="float-right">
                                            <el-button
                                                @click="cancelAddDialog"
                                            >{{ $t('common.btn.cancel') }}</el-button>
                                            <el-button
                                                type="primary"
                                                @click="confirmAddDialog"
                                            >{{ $t('common.btn.confirm') }}</el-button>
                                        </div>
                                    </el-col>
                                </el-row>
                            </el-dialog> -->
                        </el-main>
                        <el-footer>
                            <div class="float-right">
                                <el-button size="mini" @click="deleteCourseLabs">删除</el-button>
                                <!-- v-if="labType==1" -->
                                <el-button
                                    type="primary"
                                    
                                    size="mini"
                                    :disabled="!isEdit"
                                    @click="saveAll"
                                >保存</el-button>
                            </div>
                        </el-footer>
                    </el-container>
                </el-container>
            </el-tabs>
        </div>
    </div>
</template>
<script>
import {
    listParent,
    addCourseTag,
    bclCoursesTag,
    deleteCourseTag,
    bclHonorModuleList,
    addHonorModule,
    listHonorModuleParent,
    bclHonorModuleFindById,
    findNameByid,
    deleteHonorModule,
    updateHonorModule,
    updateCourseTag
} from "common/src/api/culture/bachelor";
import { queryDic , findTrainingLevelByProjId} from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import bus from "common/src/utils/bus";
export default {
    data() {
        return {
            lableGradeID:'',
            activeName: "nonPublic",
            showCourseDialog: false,
            showAddCourseDialog: false,
            filterText: "",
            labType: 2, //1为公共选修课，2为非公共选修课
            isEdit: false,
            courseSetting:'',
            sonName:'',
            parentName:'',
            multipleSelection: [],
            treeData: [],
            defaultProps: {
                children: "children",
                label: "label"
            },
            detailForm: {},
            options: {
                courseType: [],
                college: [],
                coutseTag:[],
                trainingLevel:[],
            },
            // 添加分类
            classifyForm: {
                name: "",
                trainingLevel: "",
                startYear: "",
                endYear: "",
                courseType: "",
                shortName:""
            },
            addCourseForm: [],
            classifyOptions: {
                courseType: []
            },
            courseList: [],
            queryForm: {},
            courseRules: {
                name: [
                    {
                        required: true,
                        message: "请输入标签名称",
                        trigger: "change"
                    },
                    {
                        min: 1,
                        max: 32,
                        message: "长度在 1 到 32 个字符",
                        trigger: "change"
                    }
                ],
                trainingLevel: [
                    {
                        required: true,
                        message: "请选择培养层次",
                        trigger: "change"
                    }
                ],
                startYear: [
                    {
                        required: true,
                        message: "请选择年级",
                        trigger: "change"
                    }
                ],
                shortName: [
                    {
                        required: true,
                        message: "请输入标签简称",
                        trigger: "change"
                    },
                    {
                        min: 1,
                        max: 32,
                        message: "长度在 1 到 32 个字符",
                        trigger: "change"
                    }
                ],
            },
            // courseRule1: {
            //     startYear: [
            //         {
            //             required: true,
            //             message: "请选择年级",
            //             trigger: "change"
            //         }
            //     ],
            // },
            // courseRule2: {
            //     startYear: [
            //         {
            //             required: true,
            //             message: "请选择年级",
            //             trigger: "change"
            //         }
            //     ],
            // },
            newId:this.$route.query.id,
            isEditCourseLab: false,
            isEditCoutseTag: false,
            tagList:[]//保存更改的标签
        };
    },
    watch: {
        filterText(val) {
            this.$refs.tree.filter(val);
        },
        // labType(newVal, oldVal){
        //     if (newVal) {
        //         this.clear();
        //         this.init();
        //         this.getCourseType();
        //     }
        // },
        newId(newVal, oldVal){
            if (newVal.length > 100) {
                this.clear();
                this.init();
            }
        },
        detailForm: {
            handler(newName, oldName) {
                if(oldName){
                    this.isEdit = true;
                    this.isEditCourseLab = true;
                }
                if (newName.id !== oldName.id) {
                    this.isEdit = false;
                }
            },
            deep: true
        },
        sonName(newName, oldName){
            if (newName !== oldName) {
                this.isEdit = true;
            }
        },
        parentName(newName, oldName){
            if (newName !== oldName) {
                this.isEdit = true;
            }
        },
    },
    created() {
        this.clear();
        this.initTrainingLevelOptions();
        this.init();
        this.getCourseType();
    },
    methods: {
        initTrainingLevelOptions() {
            findTrainingLevelByProjId('1').then(res => {
                if (res.code === 200) {
                    this.loadTrainingLevelOptions("trainingLevel", res.data);
                }
            });
        },
        loadTrainingLevelOptions(optionKey, dataObj) {
            this.options[optionKey] = [];
            _.each(dataObj, level => {
                this.options[optionKey].push({
                    label:
                        "en" === this.$store.getters.language
                            ? level.nameEN
                            : level.nameCN,
                    value: level.code
                });
            });
            console.log(this.options.trainingLevel)
        },
        init() {
            this.activeName="nonPublic";
            this.labType=2;
            this.getTreeData();
            //this.getFacultys();
        },
        clear(){
            this.treeData=[];
            this.courseList=[];
            this.detailForm=[]
            this.classifyForm={}
        },
        // 获取左边导航内容
        getTreeData() {
            console.log('this.labType')
            let data = {
                nameCN: this.filterText
            };
            if(this.labType == 2){
                bclCoursesTag(data).then(res => {
                    if (res.code == 200) {
                        let data = res.data.map(item => {
                            return {
                                id: item.id,
                                label:
                                    "en" === this.$store.getters.language
                                        ? item.nameEN
                                        : item.nameCN,
                                nameCN: item.nameCN,
                                trainingLevel: item.trainingLevel,
                                parentID: item.parentID,
                                startYear: item.startYear + '',
                                endYear: item.endYear + '',
                                shortName: item.shortName,
                            };
                        });
                        this.setTree(data);
                    }
                });
            }else{
                bclHonorModuleList(data).then(res => {
                    if (res.code == 200) {
                        let data = res.data.map(item => {
                            return {
                                id: item.id,
                                label:
                                    "en" === this.$store.getters.language
                                        ? item.nameEN
                                        : item.nameCN,
                                trainingLevel: item.trainingLevel,
                                parentID: item.parentID,
                                startYear: item.startYear + '',
                                endYear: item.endYear==0?"" :+ item.endYear+'',
                            };
                        });
                        this.setTree(data);
                    }
                });
            }
            
        },
        setTree(data) {
            let parent = data.filter(item => {
                return item.parentID == 0;
            });
            let child = data.filter(item => {
                return item.parentID > 0;
            });
            if (child.length > 0) {
                parent.forEach(par => {
                    par.children = [];
                    child.forEach(chi => {
                        if (par.id == chi.parentID) {
                            chi.courseType = chi.parentID;
                            par.children.push(chi);
                        }
                    });
                });
            }
            this.treeData = parent;
            this.options.courseType = parent;
            if (parent.length > 0) {
                this.detailForm = parent[0];
                console.log(parent)
                if(this.labType=='1'){
                    this.findNameByid(this.detailForm.id);
                }
            }
        },
        getCourseType() {
            let data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_KCBQ"]
            };
            queryDic(data).then(res => {
                if (res.code == 200) {
                    UTILS.fillSelect(
                        {
                            coutseTag: "X_KCBQ",
                        },
                        res.data,
                        this.options
                    );
                }
            });
        },
        // 更换公共非公共选修课页签
        handleClick(tab, event) {
            if (tab.name == "nonPublic") {
                this.labType = 2;
                this.detailForm = []
            } else {
                this.labType = 1;
                this.detailForm = []
            }
            this.filterText = "";
            this.clear();
            this.getTreeData();
        },
        filterNode(value, data) {
            if (!value) return true;
            return data.label.indexOf(value) !== -1;
        },
        // 点击查看详情
        nodeClick(data, node, tree) {
            this.detailForm = data;
            console.log('data')
            console.log(data)
             if(this.labType=='1'){
                this.findNameByid(this.detailForm.id);
            }
        },
         // 查询本科生课程荣誉模块父子课程
        findNameByid(id) {
            findNameByid(id).then(res => {
                if (res.code == 200) {
                    this.parentName = res.data.parentName
                    this.sonName = res.data.sonName
                    
                }
            });
        },
        // 获取学院
        // getFacultys() {
        //     getFacultys().then(res => {
        //         if (res.code == 200) {
        //             res.data.splice(
        //                 res.data.findIndex(c => c.deptCode == "-10000"),
        //                 1
        //             );
        //             this.options.college = res.data;
        //             this.options.college.forEach(c => {
        //                 c.value = c.deptCode;
        //                 c.label =
        //                     "en" == this.$store.getters.language
        //                         ? c.deptNameEn
        //                         : c.deptName;
        //             });
        //         }
        //     });
        // },
        // getCourseList() {
        //     let data = {
        //         college: this.queryForm.college,
        //         condition:this.queryForm.condition,
        //         pageNum_: 1,
        //         pageSize_: 100
        //     };
        //     getCourseList(data).then(res => {
        //         if (res.code == 200) {
        //             let courseList = res.data.list.map(item => {
        //                 return {
        //                     id: item.id,
        //                     code: item.code,
        //                     name: item.name,
        //                     nameEn: item.nameEn,
        //                     college: item.college,
        //                     credits: item.credits,
        //                     period: item.period
        //                 };
        //             });
        //             this.addCourseForm = courseList;
        //         }
        //     });
        // },
        // 课程维护
        addCourse() {
            if(!this.detailForm.endYear || this.detailForm.endYear == 0){
                this.detailForm.endYear = "永久"
            }
            let trainingLevelCN
            if(this.detailForm.trainingLevel){
                this.options.trainingLevel.forEach(d =>{
                if(d.value == this.detailForm.trainingLevel){
                    trainingLevelCN = d.label;
                    }
                })
            }
            let courseMaintenance =  {
                    id: this.detailForm.id,
                    nameCN: this.parentName,
                    trainingLevel: this.detailForm.trainingLevel,
                    trainingLevelCN: trainingLevelCN,
                    courseType: this.sonName,
                    startYear:this.detailForm.startYear,
                    endYear:this.detailForm.endYear,
                }
            
            sessionStorage.setItem("courseMaintenance",JSON.stringify(courseMaintenance));
            this.$router.push({
                path:'/bclCourseMaintenance',
                params: {
                    id: this.detailForm.id,
                    nameCN: this.detailForm.nameCN,
                    trainingLevel: this.parentName,
                    trainingLevelCN: trainingLevelCN,
                    courseType: this.sonName,
                    startYear:this.detailForm.startYear,
                    endYear:this.detailForm.endYear,
                }
            })
        },
        addCourseSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 取消对话框课程分类
        cancelAddCourseLab() {
            this.showCourseDialog = false;
        },
        cancelAddDialog() {
            this.showAddCourseDialog = false;
        },
        resetFormValidate() {
            // 清除表单校验
            this.$refs.classifyForm.resetFields();
            if(this.classifyForm.endYear){
                 this.classifyForm.endYear = ""
            }
           
        },
        // 添加课程标签/荣誉
        addCourseCategory() {
            console.log(this.labType)
            if(this.labType == 2){
                this.dialogTitle = "添加标签";
            }else{
                this.dialogTitle = "添加";
            }
             this.classifyForm={}
             this.showCourseDialog = true;
             this.getParentCourseLabel();

        },
        addCourseLabs() {
            //添加课程标签
            this.$refs.classifyForm.validate(valid => {
                if (!valid) {
                    return;
                }
                let parms;
                if(this.classifyForm.startYear && this.classifyForm.endYear){
                    if(this.classifyForm.startYear*1>this.classifyForm.endYear*1){
                        this.$message({
                                    type: "warning",
                                    message: "开始时间不能小于结束时间"
                                });
                        return;
                    }else{
                        parms = {
                            nameCN: this.classifyForm.name,
                            trainingLevel: this.classifyForm.trainingLevel,
                            startYear: this.classifyForm.startYear*1,
                            endYear: this.classifyForm.endYear*1,
                        };
                    }
                }else{
                      parms = {
                            nameCN: this.classifyForm.name,
                            trainingLevel: this.classifyForm.trainingLevel,
                            startYear: this.classifyForm.startYear*1
                           
                        };
                }
                if (this.classifyForm.courseType) {
                    parms.parentID = this.classifyForm.courseType;
                }else{
                    parms.parentID = 0;
                }
                if(this.labType == 2){
                    parms.shortName = this.classifyForm.shortName;
                    addCourseTag(parms)
                    .then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "添加成功"
                            });
                            this.showCourseDialog = false;
                            this.clear();
                            this.getTreeData();
                        }
                    })
                    .catch(error => {
                        this.$message({
                            type: "error",
                            message: "添加失败"
                        });
                    });
                }else{
                    addHonorModule(parms)
                    .then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "添加成功"
                            });
                            this.showCourseDialog = false;
                            this.clear();
                            this.getTreeData();
                        }
                    })
                    .catch(error => {
                        this.$message({
                            type: "error",
                            message: "添加失败"
                        });
                    });
                }
            });
        },
        // 查询归属课程标签
        getParentCourseLabel() {
            if(this.labType == 2){
                listParent().then(res => {
                    if (res.code == 200) {
                        this.classifyOptions["courseType"] = [];
                        _.each(res.data, item => {
                            this.classifyOptions["courseType"].push({
                                label:
                                    "en" === this.$store.getters.language
                                        ? item.nameEN
                                        : item.nameCN,
                                id: item.id
                            });
                        });
                    }
                });
            }else{
                listHonorModuleParent().then(res => {
                    if (res.code == 200) {
                        this.classifyOptions["courseType"] = [];
                        _.each(res.data, item => {
                            this.classifyOptions["courseType"].push({
                                label:
                                    "en" === this.$store.getters.language
                                        ? item.nameEN
                                        : item.nameCN,
                                id: item.id
                            });
                        });
                    }
                });
            }
        },
        //删除课程标签
        deleteCourseLabs() {
            if(!this.detailForm.id){
                this.$message({
                    type: "warning",
                    message: "请先选择要删除的课程"
                });
                return
            }
            if(this.labType == 2){
                if(this.detailForm.parentID == 0){
                        this.$confirm("此操作将删除父级下的所有子课程标签, 是否继续?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    })
                    .then(() => {
                        deleteCourseTag(this.detailForm.id)
                        .then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    type: "success",
                                    message: "删除成功"
                                });
                                this.clear();
                                this.getTreeData();
                                //this.getFacultys();
                            }
                        })
                        .catch(error => {
                            this.$message({
                                type: "error",
                                message: "删除失败"
                            });
                        });
                    })
                }else{
                    this.$confirm("此操作将删除所选中的子课程标签, 是否继续?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    })
                    .then(() => {
                        deleteCourseTag(this.detailForm.id)
                        .then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    type: "success",
                                    message: "删除成功"
                                });
                                this.clear();
                                this.getTreeData();
                                //this.getFacultys();
                            }
                        })
                        .catch(error => {
                            this.$message({
                                type: "error",
                                message: "删除失败"
                            });
                        });
                    })
                }
            }else{
                if(this.detailForm.parentID == 0){
                    this.$confirm("此操作将删除父级下的所有子课程标签, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                    })
                    .then(() => {
                        deleteHonorModule(this.detailForm.id)
                        .then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    type: "success",
                                    message: "删除成功"
                                });
                                this.clear();
                                this.getTreeData();
                                //this.getFacultys();
                            }
                        })
                        .catch(error => {
                            this.$message({
                                type: "error",
                                message: "删除失败"
                            });
                        });
                    })
                }else{
                    this.$confirm("此操作将删除所选中的子课程标签, 是否继续?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    })
                    .then(() => {
                        deleteHonorModule(this.detailForm.id)
                        .then(res => {
                            if (res.code == 200) {
                                this.$message({
                                    type: "success",
                                    message: "删除成功"
                                });
                                this.clear();
                                this.getTreeData();
                                //this.getFacultys();
                            }
                        })
                        .catch(error => {
                            this.$message({
                                type: "error",
                                message: "删除失败"
                            });
                        });
                    })
                }
            }
        },
        // 保存
        saveAll() {
            if(this.labType == 2){
                this.isEditCourseLab=false;
                if(!this.detailForm.id){
                    this.$message({
                        type: "warning",
                        message: "请先选择需要修改的课程标签"
                    });
                    return
                }
                if(!this.detailForm.startYear){
                    this.$message({
                        type: "warning",
                        message: "请先选择需要修改的年级"
                    });
                    return
                }
                if(!this.detailForm.shortName){
                    this.$message({
                        type: "warning",
                        message: "请填写简称"
                    });
                    return
                }
                let parms;
                if(this.detailForm.startYear && this.detailForm.endYear){
                    if(this.detailForm.startYear*1>this.detailForm.endYear*1){
                        this.$message({
                                    type: "warning",
                                    message: "开始时间不能小于结束时间"
                                });
                        return;
                    }else{
                        parms = {
                            id: this.detailForm.id,
                            nameCN: this.detailForm.nameCN,
                            trainingLevel: this.detailForm.trainingLevel,
                            startYear: this.detailForm.startYear*1,
                            endYear: this.detailForm.endYear*1,
                        };
                    }
                }else{
                    parms = {
                        id: this.detailForm.id,
                        nameCN: this.detailForm.nameCN,
                        trainingLevel: this.detailForm.trainingLevel,
                        startYear: this.detailForm.startYear*1,
                        
                    };
                }
                if(this.detailForm.courseType){
                    parms.parentID=this.detailForm.courseType
                }else{
                    parms.parentID = 0;
                }
                parms.shortName=this.detailForm.shortName
                updateCourseTag(parms)
                    .then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "保存成功"
                            });
                            //this.findCommonLabCourse(this.detailForm.id);
                            this.getTreeData();
                        }
                    })
                    .catch(error => {
                        this.$message({
                            type: "error",
                            message: "保存失败"
                        });
                    });
                    
            }
            if (this.labType == 1) {
                if(!this.detailForm.id){
                    this.$message({
                        type: "warning",
                        message: "请先选择需要修改的荣誉课程"
                    });
                    return
                }
                if(!this.detailForm.startYear){
                    this.$message({
                        type: "warning",
                        message: "请先选择需要修改的年级"
                    });
                    return
                }
                let parms;
                if(this.detailForm.startYear && this.detailForm.endYear){
                    if(this.detailForm.startYear*1>this.detailForm.endYear*1){
                        this.$message({
                                    type: "warning",
                                    message: "开始时间不能小于结束时间"
                                });
                        return;
                    }else{
                        parms = {
                            id: this.detailForm.id,
                            trainingLevel: this.detailForm.trainingLevel,
                            startYear: this.detailForm.startYear*1,
                            endYear: this.detailForm.endYear*1,
                        };
                    }
                }else{
                    parms = {
                        id: this.detailForm.id,
                        trainingLevel: this.detailForm.trainingLevel,
                        startYear: this.detailForm.startYear*1,
                        
                    };
                }
                if(this.detailForm.parentID != 0){
                    parms.nameCN=this.sonName
                }else{
                    parms.nameCN=this.parentName
                }
                 if(this.detailForm.courseType){
                    parms.parentID=this.detailForm.courseType
                }else{
                    parms.parentID = 0;
                }
                updateHonorModule(parms)
                    .then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: "保存成功"
                            });
                            this.getTreeData();
                        }
                    })
                    .catch(error => {
                        this.$message({
                            type: "error",
                            message: "保存失败"
                        });
                    });
            }
        }
    }
};
</script>
<style scoped>
.coursemap {
    font-size: 12px;
    margin-bottom: 15px;
}
.el-tabs--border-card {
    background: #fff;
    border: none;
    -webkit-box-shadow: none;
    box-shadow: none;
}
.el-aside {
    padding: 0 20px;
    color: #333;
    /* text-align: center; */
    border-right: 1px solid #cccc;
}

.el-main {
    padding: 20px;
    color: #333;
}
.el-footer {
    border-top: 1px solid #cccc;
    color: #333;
    line-height: 60px;
    text-align: right;
}
.addCourseBtn {
    margin-bottom: 15px;
}
.el-date-editor.el-input, .el-date-editor.el-input__inner{
    width:150px !important;
}
</style>

